# -*- coding: utf-8 -*-
"""
# @created on : 9月 2021/9/14 19:20
# @author     : kevin
# @file       : logger.py
# @software   : PyCharm
# @project    : auto_interface_test


@license: (C) Copyright 2019-2025, Corporation Limited.
@desc:
"""
import logging
import os
from utils.operation_path import OperationPath
import time


class Logger:
    def __init__(self):
        op = OperationPath()
        log_path = os.path.join(op.get_current_path(), 'log')
        today = time.strftime("%Y%m%d", time.localtime())
        self.log_file = os.path.join(log_path, today, 'log.log')
        op.check_path(os.path.split(os.path.realpath(self.log_file))[0])

    def logger(self, level, msg):
        """
        保存log数据
        :param level: 日志记录级别 info error debug
        :param msg: log信息
        """
        logging.basicConfig(level=logging.DEBUG,
                            format='%(asctime)s %(levelname)s %(message)s',
                            datefmt='%a, %d %b %Y %H:%M:%S',
                            filename=self.log_file,
                            filemode='a')
        log = logging.getLogger()
        logging.FileHandler(self.log_file, encoding='utf-8')
        if level == 'info':
            log.info(msg)
        elif level == 'error':
            log.error(msg)
        else:
            log.debug(msg)
